<?php
/* @var $this TaskController */
/* @var $model Task */

$this->breadcrumbs=array(
	'Tasks'=>array('index'),
	'Manage',
);

$this->menu=array(
	array('label'=>'查看任务', 'url'=>array('admin')),
	array('label'=>'添加任务', 'url'=>array('create')),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$('#task-grid').yiiGridView('update', {
		data: $(this).serialize()
	});
	return false;
});
");
?>

<h1>Manage Tasks</h1>

<?php 

if(Yii::app()->user->name === 'admin'){ 
$this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'task-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
	'columns'=>array(
		
		'id',
		array(
		'name'=>'title',
		'value'=>'"<div title=\"".$data->content."\" rel=\"tooltip\">".$data->title."<div>"',
		'type'=>'raw'
		), 

		array(
		'name'=>'name',
		'value'=>'"<div title=\'".substr($data->starttime,0,10)."<br>".substr($data->endtime,0,10)."<br>发送人：".$data->username."\' rel=\'tooltip\'>".($data->name==="send"?"发送":($data->name==="check"?"扫描":"等待")).($data->sendofmax==0?"所有":$data->sendofmax."条")."到 ".($data->district===\'all\'?\'全国\':$data->district)."<div>"',
		'type'=>'raw'
		), 

		array(
		'name'=>'sendofmax',
		'value'=>'"<div title=\'"."最大发送量：".$data->sendofmax."<br>总发送量：".$data->sendtoday."<br>已发放量：".$data->toindex."\' rel=\'tooltip\'>".($data->sendtoday >= $data->sendofmax?"<div class=disconnection title=\'$data->lasttime\'></div>已完成  ".CHtml::link(\'查看报表\',\'index.php?r=tasklog/admin&Tasklog[taskid]=\'.$data->id):"<div class=connection title=\'$data->lasttime\'></div>执行中... ".(round($data->sendtoday/$data->sendofmax)*100)."%")',
		'type'=>'raw'
		), 
		array(
			'class'=>'CButtonColumn',
		),
	),
)); 
} else {

$this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'task-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
	'columns'=>array(
		
		array(
		'name'=>'id',
		'value'=>'CHtml::link($data->id,\'index.php?r=tasklog/admin&Tasklog[taskid]=\'.$data->id)',
		'type'=>'raw'
		),  
		array(
		'name'=>'title',
		'value'=>'"<div title=\"".$data->content."\" rel=\"tooltip\">".$data->title."<div>"',
		'type'=>'raw'
		), 

		array(
		'name'=>'name',
		'value'=>'"<div title=\'".substr($data->starttime,0,10)."<br>".substr($data->endtime,0,10)."<br>发送人：".$data->username."\' rel=\'tooltip\'>".($data->name==="send"?"发送":($data->name==="check"?"扫描":"等待")).($data->sendofmax==0?"所有":$data->sendofmax."条")."到 ".($data->district===\'all\'?\'全国\':$data->district)."<div>"',
		'type'=>'raw'
		), 

		array(
		'name'=>'sendofmax',
		'value'=>'"<div title=\'"."最大发送量：".$data->sendofmax."<br>已发送量：".$data->sendtoday."<br>已派发量：".$data->toindex."\' rel=\'tooltip\'>".($data->sendtoday > $data->sendofmax?"<div class=disconnection title=\'$data->lasttime\'></div>任务已完成":"<div class=connection title=\'$data->lasttime\'></div>执行中... ".($data->sendofmax*$data->sendtoday/100)."%")',
		'type'=>'raw'
		)
	),
)); 

}
?>
